﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>salary_standard_details</title>
    <script src="~/lib/axios/dist/axios.js"></script>
    <script src="~/lib/vue/dist/vue.js"></script>
    <script src="~/lib/element-ui/lib/index.js"></script>
    <link href="~/lib/element-ui/lib/theme-chalk/index.css" rel="stylesheet" />
</head>
<body>
    <div id="app">
        <el-container>
            <el-header>
                <el-card class="box-card">
                    <el-col :span="4"> 薪酬标准登记 </el-col>
                </el-card>
            </el-header>
            <el-main>
                <el-card class="box-card">
                    <el-form ref="form"
                             :model="form"
                             :rules="formrule"
                             :inline="true"
                             label-width="80px">
                        <el-row>
                            <el-form-item class="_klpo">
                                <template>
                                    <el-button type="primary" @@click="submitForm('form')">提交</el-button>
                                </template>
                                <el-button @@click="eas()">返回</el-button>
                            </el-form-item>
                        </el-row>
                        <el-form-item label="薪酬标准编号" prop="standard_id" label-width="96px">
                            <el-input v-model="form.standard_id" style="width: 148px" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="薪酬标准名称" prop="standard_name" label-width="107px">
                            <el-input v-model="form.standard_name" style="width: 210px"></el-input>
                        </el-form-item>
                        <el-form-item label="薪酬总额" prop="salary_sum">
                            <el-input v-model="form.salary_sum" style="width: 162px" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="制定人" prop="designer" label-width="65px">
                            <template>
                                <el-select v-model="form.designer" placeholder="请选择登记人" style="width: 200px ">
                                    <el-option v-for="item in listm"
                                               :key="item.u_id"
                                               :label="item.u_true_name"
                                               :value="item.u_true_name">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item label="登记人" prop="register" label-width="54px">
                            <template>
                                <el-select v-model="form.register" placeholder="请选择登记人" style="width: 190px ">
                                    <el-option v-for="item in listm"
                                               :key="item.u_id"
                                               :label="item.u_true_name"
                                               :value="item.u_true_name">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item prop="regist_time" label="登记时间" label-width="96px">
                            <el-date-picker style="width: 221px " :disabled="true" type="datetime" placeholder="选择日期" v-model="form.regist_time"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="备注" prop="remark" label-width="40px">
                            <el-input type="textarea" v-model="form.remark" style="width: 1072px " autosize></el-input>
                        </el-form-item>
                        <el-form-item :style=div1>
                            <template>
                                <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @@change="handleCheckAllChange">全选</el-checkbox>
                                <el-form-item>
                                    <template>
                                        <el-button type="primary" @@click="aout()" style="margin-left: 40px;">请选择薪酬组成</el-button>
                                    </template>
                                </el-form-item>
                                <div style="margin: 15px 0;"></div>
                                <el-checkbox-group v-model="checkedCities" @@change="handleCheckedCitiesChange">
                                    <el-checkbox v-for="item in cities" :label="item" :key="item">{{item}}</el-checkbox>
                                </el-checkbox-group>
                            </template>
                        </el-form-item>
                        <el-table :data="list" :style=div border stripe>
                            <el-table-column prop="pbc_id"
                                             label="序号"
                                             align="center">
                            </el-table-column>
                            <el-table-column prop="attribute_name"
                                             label="薪酬项目名称"
                                             align="center">
                            </el-table-column>
                            <el-table-column label="金额" align="center">
                                <template slot-scope="scope">
                                    <el-input v-model.number="scope.row.mony" @@input="js(scope.row)" oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-form>
                </el-card>
            </el-main>
        </el-container>
       
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#app",
            data: {
                list: [],//表格数据
                je:[],//薪酬名称和金额
                div: "display: none;",//控制薪酬表格显示
                div1: "display: inherit;",//控制复选框的显示
                listm:[],//用户
                checkedCities: ['基本工资'],//复选框默认显示
                cityOptions: [],//初始数据
                cities: [],//初始显示数据
                checkAll: false,
                isIndeterminate: true,
                form: {
                    standard_id: '',
                    standard_name: '',
                    designer: '',
                    register: '',
                    checker: '',
                    changer: '',
                    regist_time: '',
                    salary_sum: '',
                    remark: '',
                    salary: '',
                    formrule:'',
                },
                formrule: {
                    standard_name: [
                        { required: true, message: '请输入标准名', trigger: 'blur' }
                    ],
                    designer: [
                        { required: true, message: '请选择制定人', trigger: 'change' }
                    ],
                    salary_sum: [
                        { required: true, message: '请输入金额', trigger: 'blur' }
                    ],
                }
            },
            methods: {
                js(row) {
                    this.je = [];
                    row.mony = row.mony == "" ? 0 : parseInt(row.mony);
                    this.form.salary_sum = 0;//薪酬总额
                    for (var index in this.list) {
                        if (this.list[index].mony != null) {
                            this.form.salary_sum += parseInt(this.list[index].mony);//金额相加
                            var ohj = {};
                            ohj.pbc_id = this.list[index].pbc_id;//薪酬id
                            ohj.attribute_name = this.list[index].attribute_name;//薪酬名字
                            ohj.mony = this.list[index].mony;//薪酬金额
                            this.je.push(ohj);
                        }
                    }
                },
                submitForm(formName) {
                    //表单验证
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                                this.$confirm('此操作将提交薪酬信息, 是否提交?', '提示', {
                                    confirmButtonText: '确定',
                                    cancelButtonText: '取消',
                                    type: 'warning'
                                }).then(() => {
                                    //薪酬标准添加
                                    axios.get('/salary_standard/Insert', {
                                        params: {
                                            standard_id: this.form.standard_id,
                                            standard_name: this.form.standard_name,
                                            designer: this.form.designer,
                                            register: this.form.register,
                                            regist_time: this.form.regist_time,
                                            salary_sum: this.form.salary_sum,
                                            remark: this.form.remark,
                                        }
                                    })
                                        .then(res => {
                                            console.info(res);
                                            if (res.data == 1) {
                                                for (let index in this.je) {
                                                    //薪酬标准详细添加
                                                    axios.get('/salary_standard/Inserte', {
                                                        params: {
                                                            standard_id: this.form.standard_id,
                                                            standard_name: this.form.standard_name,
                                                            item_id: this.je[index].pbc_id,
                                                            item_name: this.je[index].attribute_name,
                                                            salary: this.je[index].mony,
                                                        }
                                                    })
                                                        .then(res => {
                                                            console.info(res);
                                                        })
                                                        .catch(err => {
                                                            console.info(err);
                                                        })
                                                }
                                                this.$message({
                                                    type: 'success',
                                                    message: '保存成功!'
                                                });
                                                this.eas();
                                            }
                                        })
                                        .catch(err => {
                                            console.info(err);
                                        })
                                }).catch(() => {
                                    this.$message({
                                        type: 'info',
                                        message: '已取消提交'
                                    });
                                });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请填写完整信息!'
                            });
                            return false;
                        }
                    });
                },
                eas() {
                    this.div = "display: none;"//隐藏薪酬表格
                    this.div1 = "display: inherit;"//显示复选框
                    this.list = [];//清空复选框数据
                    this.$refs['form'].resetFields();//清空所有表单
                    //查询当前登录人
                    axios.get('/users/Fill/' +@ViewBag.id)
                        .then(res => {
                            console.info(res);
                            this.form.register = res.data[0].u_true_name;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                    this.checkedCities = ['基本工资'];
                    this.isIndeterminate = false;
                },
                aout() {
                    this.div = "display: inherit;height: 244px; overflow: auto;"//显示薪酬表格
                    this.div1 = "display: none;"//隐藏复选框
                    //获取当前复选框选中的节点值查询
                    for (var index in this.checkedCities) {
                        //查询公共属性薪酬数据
                        axios.get('/salary_standard/Auto', {
                            params: {
                                name: this.checkedCities[index],
                            }
                        })
                            .then(res => {
                                console.info(res);
                                this.list.push(res.data[0]);

                            })
                            .catch(err => {
                                console.info(err);
                            });
                    }
                    console.info(this.list);
                },
                //随机编号
                idbm() {
                    let yy = new Date().getFullYear();
                    let mm = new Date().getMonth() + 1;
                    let dd = new Date().getDate();
                    let hh = new Date().getHours();
                    let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
                    let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
                    this.form.standard_id = "KP" + yy + mm + dd + hh + mf + ss;
                },
                fill() {
                    this.idbm();
                    //用户查询
                    axios.get('/users/que', {
                    })
                        .then(res => {
                            console.info(res);
                            this.listm = res.data;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                    //当前登录人查询
                    axios.get('/users/Fill/' +@ViewBag.id)
                        .then(res => {
                            console.info(res);
                            this.form.register = res.data[0].u_true_name;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                    //公共表薪酬名称查询
                    axios.get('/config_public_char/Lexing')
                        .then(res => {
                            console.info(res);
                            for (let index in res.data) {
                                this.cityOptions.push(res.data[index].attribute_name);
                            }
                            this.cities = this.cityOptions;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                //全选按钮的改变事件
                handleCheckAllChange(val) {
                    this.checkedCities = val ? this.cityOptions : [];
                    this.isIndeterminate = false;
                },
                //多个复选框改变事件
                handleCheckedCitiesChange(value) {
                    let checkedCount = value.length;
                    this.checkAll = checkedCount === this.cities.length;
                    this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
                },
                get() {
                    //当前时间
                    this.form.regist_time = new Date();
                },
            },
            mounted() {
                //时间计时器
                setInterval(this.get, 1000);
            },
            //可以对vue的数据和方法进行操作,不能对DOM进行操作
            created: function () {
                this.fill();
            }
        });
    </script>
    <style>
        .el-col-4 {
            width: 20%;
            font-size: 15px;
            font-weight: 900;
            line-height: 0px;
        }

        element.style {
            height: 100%;
            width: 1239px;
        }
        .el-card__body {
            padding: 35px;
        }
        .el-button.is-circle {
            border-radius: 50%;
            padding: 12px;
            position: relative;
            top: -10px;
            right: -570px;
        }
        ._klpo {
            float: right;
        }
    </style>
</body>
</html>
